package com.demo.task;

import com.demo.constant.CacheConstants;
import com.demo.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author gxd
 * @since 2025/6/1
 */
@Slf4j
@Component
public class SystemTask {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private SysUserService userService;

    // @Scheduled(fixedRate = 10000)
    public void userTask() {
        log.info("----------定时任务启动，加载[用户大屏数据]到Redis----------");
        // 分批查询-当天每半小时一分组，求每个半小时的总数
        redisTemplate.opsForValue().set(CacheConstants.USER_COUNT_24_KEY, userService.buildUserBatch());
    }
}
